package com.ou.csbs.capstone.views.worldwind;

import java.awt.event.KeyListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseListener;

import gov.nasa.worldwind.BasicModel;
import gov.nasa.worldwind.awt.WorldWindowGLJPanel;
import gov.nasa.worldwind.event.SelectListener;
import gov.nasa.worldwind.layers.Layer;

/**
 * The WorldWind Canvas and Model are instantiated here. Along with these, several static helper methods are defined to aid in the readability of other classes.
 * 
 * @author Senior Capstone
 */
public class WorldWindCanvas {
	static WorldWindowGLJPanel worldWindCanvas = new WorldWindowGLJPanel();
	static BasicModel worldWindModel = new BasicModel();
	public static void initialize(){
		//create a WorldWind main object
		worldWindCanvas.setModel(worldWindModel);

	}
	public static void turnLayerOn(String layerName){
		//enable layer in WorldWind
		worldWindCanvas.getModel().getLayers().getLayerByName(layerName).setEnabled(true);
	}
	public static void turnLayerOff(String layerName){
		//disable layer in WorldWind
		worldWindCanvas.getModel().getLayers().getLayerByName(layerName).setEnabled(false);
	}
	public static void addLayer(Layer layer){
		//add layer to WorldWind's layer list
		worldWindCanvas.getModel().getLayers().add(layer);
	}
	public static void removeLayer(String layerName){
		Layer toRemove = worldWindCanvas.getModel().getLayers().getLayerByName(layerName);
		if(toRemove != null)
			worldWindCanvas.getModel().getLayers().remove(toRemove);
	}
	public static void addSelectListener(SelectListener listener){
		worldWindCanvas.getInputHandler().addSelectListener(listener);
	}
	public static void addMouseListener(MouseListener listener){
		worldWindCanvas.getInputHandler().addMouseListener(listener);
	}
	public static void addMouseMotionListener(MouseMotionListener listener){
		worldWindCanvas.getInputHandler().addMouseMotionListener(listener);
	}
	public static void addKeyListener(KeyListener listener){
		worldWindCanvas.getInputHandler().addKeyListener(listener);
	}
	public static void removeSelectListener(SelectListener listener){
		worldWindCanvas.getInputHandler().removeSelectListener(listener);
	}
	public static void removeMouseListener(MouseListener listener){
		worldWindCanvas.getInputHandler().removeMouseListener(listener);
	}
	public static void removeMouseMotionListener(MouseMotionListener listener){
		worldWindCanvas.getInputHandler().removeMouseMotionListener(listener);
	}
	public static void removeKeyListener(KeyListener listener){
		worldWindCanvas.getInputHandler().removeKeyListener(listener);
	}
	public static WorldWindowGLJPanel getWorldWindow(){
		return worldWindCanvas;
	}
	public static BasicModel getWorldWindModel(){
		return worldWindModel;
	}
}
